package com.example.cameraprototipo;

import java.io.File;
import java.io.IOException;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{
		private Button btn1, btn2;
		private TextView red, blue, green;
		private String r = "Red: ", g = "Green: ", b = "Blue: ";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = (Button)findViewById(R.id.button1);
        btn2 = (Button)findViewById(R.id.button2);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        red = (TextView)findViewById(R.id.redText);
        blue = (TextView)findViewById(R.id.blueText);
        green = (TextView)findViewById(R.id.greenText);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

	public void onClick(View v) 
	{
		
		// TODO Auto-generated method stub
		// Create an output file.
		if (v.getId() == btn1.getId())
		{
			File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
			Uri outputFileUri = Uri.fromFile(file);
			// Generate the Intent.
			Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
			intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
			startActivityForResult(intent, 1);
		}
		
		else if (v.getId() == btn2.getId())
		{
			File file = new File(Environment.getExternalStorageDirectory(), "50reais.jpg");
			btn1.setText("."+file.getAbsoluteFile());
			ImageView IV = (ImageView) findViewById(R.id.imageView1);
			//Bitmap bMap =
			Bitmap bMap = BitmapFactory.decodeFile(""+file.getAbsoluteFile());
			IV.setImageBitmap(bMap);
			red.setText(r+Color.red(bMap.getPixel(0, 0)));
			blue.setText(b+Color.blue(bMap.getPixel(0, 0)));
			green.setText(g+Color.green(bMap.getPixel(0, 0)));
			
			//bMap.eraseColor(-255);
		}
		
	}
	
}
